package finalcase;

import java.util.ArrayList;

public class Test {
    public static void main(String[] args) {
        Cat bosi = new Cat("xiaoming",1, "波斯猫", "鱼");
        Cat lihua = new Cat("xiaohei",2,"狸花猫","饼干");
        Dog taidi = new Dog("taidi",3,"泰迪","肉");
        Dog hsq = new Dog("hsq",4,"哈士奇","拆墙");
        ArrayList<Dog> dogList = new ArrayList<>();
        dogList.add(taidi);
        dogList.add(hsq);
        keepDogPet(dogList);
        ArrayList<Cat> catList = new ArrayList<>();
        catList.add(bosi);
        catList.add(lihua);
        keepDogPet(catList);

    }
    //? 泛型的通配符
    public static void keepDogPet(ArrayList<? extends Animal> list){
        for(Animal ele:list){
            if(ele instanceof Dog){
                ((Dog) ele).eat();
            }
            else if(ele instanceof Cat){
                ((Cat) ele).eat();
            }
        }
    }
}
